<include file="public@header" />
<style type="text/css">
	#goods_list{
		max-height: 240px;
		overflow-x:hidden;
		overflow-y: auto;
	}
</style>
</head>
<body>
	<div class="wrap">
		<ul class="nav nav-tabs">
			<li ><a href="{:url('Liveing/index')}">直播列表</a></li>
			<li class="active"><a >{:lang('ADD')}</a></li>
		</ul>
		<form method="post" class="form-horizontal js-ajax-form margin-top-20" action="{:url('Liveing/addPost')}">

            <div class="form-group">
				<label for="input-uid" class="col-sm-2 control-label"><span class="form-required">*</span>用户ID</label>
				<div class="col-md-6 col-sm-10">
					<input type="text" class="form-control" id="input-uid" name="uid">
				</div>
			</div>
			<div class="form-group">
				<label for="input-live_type" class="col-sm-2 control-label"><span class="form-required">*</span>直播类型</label>
				<div class="col-md-6 col-sm-10">
                    <select class="form-control" name="live_type" id="live_type">
                        <option value="0">直播间</option>
                        <option value="1">语音聊天室</option>
                    </select>
				</div>
			</div>
            <div class="form-group" id="liveclass">
				<label for="input-type" class="col-sm-2 control-label"><span class="form-required">*</span>直播分类</label>
				<div class="col-md-6 col-sm-10">
                    <select class="form-control" name="liveclassid">
                    	<option value="0">默认分类</option>
                        <volist name="liveclass" id="v">
                        <option value="{$v['id']}">{$v['name']}</option>
                        </volist>
                    </select>
				</div>
			</div>
            
            <div class="form-group" id="type">
				<label for="input-type" class="col-sm-2 control-label"><span class="form-required">*</span>房间类型</label>
				<div class="col-md-6 col-sm-10">
                    <select class="form-control" name="type" id="cdn">
                        <volist name="type" id="v">
                        <option value="{$key}">{$v}</option>
                        </volist>
                    </select>
				</div>
			</div>

			<div class="form-group" id="goods">
				<label for="input-goodsid" class="col-sm-2 control-label"><span class="form-required">*</span>关联商品</label>
				<div class="col-md-6 col-sm-10">
					<p id="goods_list"><input type="text" class="form-control" id="input-goodsid" name="goodsid" readonly></p>
					<input type="button" value="选择商品" id="goods_select">
					<p class="help-block">直播间商品列表</p>
				</div>
			</div>
            
            <div class="form-group" id="cdn_switch_1" style="display:none;">
				<label for="input-type_val" class="col-sm-2 control-label"><span class="form-required">*</span>密码或价格</label>
				<div class="col-md-6 col-sm-10">
					<input type="text" class="form-control" id="input-type_val" name="type_val">
				</div>
			</div>
            
            
            <div class="form-group">
				<label for="input-pull" class="col-sm-2 control-label"><span class="form-required">*</span>视频地址</label>
				<div class="col-md-6 col-sm-10">
					<input type="text" class="form-control" id="input-pull" name="pull" value="">视频格式：MP4
				</div>
			</div>
            
            <div class="form-group" id="anyway">
				<label for="input-words" class="col-sm-2 control-label"><span class="form-required">*</span>视频类型</label>
				<div class="col-md-6 col-sm-10">
					<select class="form-control" name="anyway">
                        <option value="0">竖屏</option>
                        <option value="1">横屏</option>
                    </select>
				</div>
			</div>

			<!--<div class="form-group" id="game">
				<label for="input-words" class="col-sm-2 control-label"><span class="form-required">*</span>开启游戏</label>
				<div class="col-md-6 col-sm-10">
					<select class="form-control" name="game">
						<option value="0">不开启游戏</option>
						<option value="1">开启智勇三张</option>
					</select>
				</div>
			</div>-->

			<div class="form-group">
				<div class="col-sm-offset-2 col-sm-10">
					<button type="submit" class="btn btn-primary js-ajax-submit">{:lang('ADD')}</button>
					<a class="btn btn-default" href="{:url('Liveing/index')}">{:lang('BACK')}</a>
				</div>
			</div>
            
		</form>
	</div>
	<script src="__STATIC__/js/admin.js"></script>
	<script src="__STATIC__/js/layer/layer.js"></script>
    <script>
	(function(){
		$("#cdn").on('change',function(){
			var v=$(this).val();
			var b=$("#cdn_switch_1");
			if(v==0){
				b.hide();
				$("#input-type_val").val('');
			}else{
				b.show();
			}
		})

		$("#live_type").on('change',function(){
			var v=$(this).val();
			if(v==0){
				$("#liveclass").show();
				$("#type").show();
				$("#anyway").show();
				$("#goods").show();

			}else{
				$("#liveclass").hide();
				$("#type").hide();
				$("#anyway").hide();
				$("#goods").hide();

			}
		});

		$("#goods_select").on('click',function(){
			var uid = $("input[name='uid']").val().trim();
			//alert(uid);
			if(!uid){
				layer.msg('请先填写用户id');
				return;
			}

			$.ajax({
				type:'post',
				url:'/admin/Liveing/getGoodsList',
				data:{uid:uid},
				dataType:'json',
				async:false,

				success:function(data){
					//console.log(data);
					var code=data.code;
					var info=data.info;
					//console.log(code);
					
					if(code != 0){
						layer.msg(data.msg);
						return;
					}

					//console.log(data.info);
					if(info == false){
						layer.msg('暂无商品列表');
						return;
					}

					var goods_list='';
					for (var i = 0; i < info.length; i++) {
						goods_list+='<input type="checkbox" name="goodsid[]" data-name="'+info[i].name+'" value="'+info[i].id+'"';
						if(info[i].issale==1){
							goods_list+='checked';
						}
						goods_list+='>'+info[i].name+'（'+info[i].id+'）';
						if(info[i].live_isshow==1){
							goods_list+='【直播间弹窗展示】';
						}
						goods_list+='<br />';
					}

					$("#goods_select").attr('disabled',true).css('color','#CCC');

					$("#goods_list").html(goods_list);


				},
				error:function(e){
					layer.msg('商品列表获取失败');
					return;
				}
			});
		});



	})()
	</script>
</body>
</html>